package com.yanqu.road.logic.activity.hotpotjump;

import com.yanqu.road.dao.impl.activity.hotpotjump.CommonActivityConfigDaoImpl;
import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.autodata.hotpotjump.HotpotJumpGrid;
import com.yanqu.road.entity.autodata.hotpotjump.HotpotJumpMainRole;
import com.yanqu.road.entity.autodata.hotpotjump.HotpotJumpUnit;
import com.yanqu.road.entity.autodata.hotpotjump.config.*;
import com.yanqu.road.entity.autodata.hotpotjump.eHotpotJumpAttr;
import com.yanqu.road.logic.activity.hotpotjump.game.HotpotJumpGameLogic;
import com.yanqu.road.logic.activity.hotpotjump.game.JumpBoardGrid;
import com.yanqu.road.logic.activity.hotpotjump.game.eHotpotJumpEffect;
import com.yanqu.road.logic.activity.hotpotjump.game.eHotpotJumpUnit;
import com.yanqu.road.pb.activity.HotpotJumpProto;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

public class HotpotJumpConfig {
    private ActivityInfo activityInfo;
    private RandomHelper randomHelper = new RandomHelper();
    private Map<String, HotpotJumpProto.HotpotJumpConfigSyncMsg.Builder> configMsgMap = new HashMap<>();

    private Map<Integer, HotpotJumpSkillConfig> skillConfigMap = new HashMap<>();
    private Map<Integer, HotpotJumpLevelConfig> levelConfigMap = new HashMap<>();
    private List<HotpotJumpMissionConfig> missionConfigs = new ArrayList<>();
    private Map<Integer, HotpotJumpModelConfig> modelConfigMap = new HashMap<>();
    private List<HotpotJumpNumConfig> numConfigList = new ArrayList<>();
    private Map<Integer, HotpotJumpPotConfig> potConfigMap = new HashMap<>();

    private List<HotpotJumpLevelConfig> mainLevelConfigs = new ArrayList<>();
    private Map<Integer, HotpotJumpLevelConfig> unitLevelConfigMap = new HashMap<>();

    /**
     * 次数回复消耗
     */
    private Property energyCost = new Property();
    /**
     * 每天次数
     */
    private int dayNum = 5;
    /**
     * 刷新技能道具
     */
    private int refreshItemId = 124173;
    private List<Property> refreshCostList = new ArrayList<>();
    /**
     * 评价配置
     */
    private HotpotJumpEvaluateConfig[] evaluateConfigs;
    /**
     * 连击配置
     */
    private HotpotJumpCombConfig[] combConfigs;
    /**
     * 最大回合
     */
    private int maxRound = 100;
    /**
     * 练习模式,最大回合
     */
    private int practiceMaxRound = 15;
    /**
     * 复活消耗
     */
    private Property reviveConsume = new Property();
    /**
     * 复活次数上限
     */
    private int reviveLimit = 1;
    /**
     * 复活恢复血量千分比
     */
    private int reviveHpRate = 500;
    /**
     * 主角拥有技能上限
     */
    private int skillMaxNum = 5;
    /**
     * boss出现的回合
     */
    private List<List<Integer>> bossRound;
    /**
     * 主角初始坐标X,Y
     */
    private Integer[] initPos;
    /**
     * 初始盘面,小怪分布
     */
    private List<List<Integer>> initialEnemyList = new ArrayList<>();
    /**
     * 额外初始小怪数量
     */
    private int extraEnemyNum = 6;
    /**
     * 触发连击技能需要的连击数
     */
    private int combSkillNeed = 6;
    /**
     * 白银触发连击技能需要的连击数
     */
    private int silverCombSkillNeed = 5;
    /**
     * 移动攻击系数,千分比
     */
    private int moveAtkMulti = 600;
    /**
     * BOSS击杀能加的当前经验值
     */
    private int bossExpAdd = 700;
    /**
     * Boss出现的顺序
     */
    private List<List<Integer>> bossSortList = new ArrayList<>();
    private List<List<Integer>> createPosRuleParams = new ArrayList<>();

    /**
     * 战令增加的积分千分比
     */
    private int tokenScoreMulti = 100;
    /**
     * 人偶道具id
     */
    private int tokenDollId = 124176;

    /**
     * 引导技能池
     */
    private List<Integer> guideSkillPool = new ArrayList<>();
    /**
     * 引导的盘面配置和参数
     */
    private String HOTPOTJUMP_GUIDE_SCENE_1;
    private String HOTPOTJUMP_GUIDE_SCENE_2;
    private String HOTPOTJUMP_GUIDE_SCENE_3;
    private int guideSelectSkillIdx = 2;

    private int hpSkillWeightCheckValue = 300;
    private int hpSkillWeightMulti = 2000;

    private int HOTPOTJUMP_ROUND_END_ADD_SCORE = 0;

    public HotpotJumpConfig(ActivityInfo tempActivityInfo, Map<String, ActivityConfig> activityConfigMap) {
        this.activityInfo = tempActivityInfo;

        skillConfigMap = new CommonActivityConfigDaoImpl<HotpotJumpSkillConfig>().getConfigMap(HotpotJumpSkillConfig.class, activityInfo.getActivityId());
        levelConfigMap = new CommonActivityConfigDaoImpl<HotpotJumpLevelConfig>().getConfigMap(HotpotJumpLevelConfig.class, activityInfo.getActivityId());
        missionConfigs = new CommonActivityConfigDaoImpl<HotpotJumpMissionConfig>().getConfigList(HotpotJumpMissionConfig.class, activityInfo.getActivityId());
        modelConfigMap = new CommonActivityConfigDaoImpl<HotpotJumpModelConfig>().getConfigMap(HotpotJumpModelConfig.class, activityInfo.getActivityId());
        numConfigList = new CommonActivityConfigDaoImpl<HotpotJumpNumConfig>().getConfigList(HotpotJumpNumConfig.class, activityInfo.getActivityId());
        potConfigMap = new CommonActivityConfigDaoImpl<HotpotJumpPotConfig>().getConfigMap(HotpotJumpPotConfig.class, activityInfo.getActivityId());

        List<HotpotJumpLevelConfig> tempMainLevelConfigs = new ArrayList<>();
        for (HotpotJumpLevelConfig levelConfig : levelConfigMap.values()) {
            if (levelConfig.getType() == 1) {
                unitLevelConfigMap.put(levelConfig.getLevel(), levelConfig);
            } else if (levelConfig.getType() == 2) {
                tempMainLevelConfigs.add(levelConfig);
            }
        }
        tempMainLevelConfigs.sort((o1, o2) -> {
            return Integer.compare(o1.getLevel(), o2.getLevel());
        });
        mainLevelConfigs = tempMainLevelConfigs;


        energyCost = PropertyHelper.parseStringToProperty(activityConfigMap.get("HOTPOTJUMP_ENERGY_ITEM_ID").getValue());
        dayNum = activityConfigMap.get("HOTPOTJUMP_ENERGY_MAX_NUM").getIntValue();
        refreshItemId = activityConfigMap.get("HOTPOTJUMP_REFRESH_ITEM_ID").getIntValue();

        for (String str : activityConfigMap.get("HOTPOTJUMP_REFRESH_GLOD_PARAM").getValue().split("\\|")) {
            Property cost = PropertyHelper.parseStringToProperty(str);
            refreshCostList.add(cost);
        }

        List<HotpotJumpEvaluateConfig> tempEvaluateList = new ArrayList<>();
        for (String str : activityConfigMap.get("HOTPOTJUMP_EVALUATION_LIMIT").getValue().split("\\|")) {
            HotpotJumpEvaluateConfig evaluateConfig = new HotpotJumpEvaluateConfig(str);
            tempEvaluateList.add(evaluateConfig);
        }
        evaluateConfigs = tempEvaluateList.toArray(new HotpotJumpEvaluateConfig[tempEvaluateList.size()]);

        List<HotpotJumpCombConfig> tempCombList = new ArrayList<>();
        for (String str : activityConfigMap.get("HOTPOTJUMP_COMBO_PARAM").getValue().split("\\|")) {
            HotpotJumpCombConfig combConfig = new HotpotJumpCombConfig(str);
            tempCombList.add(combConfig);
        }
        combConfigs = tempCombList.toArray(new HotpotJumpCombConfig[tempCombList.size()]);

        maxRound = activityConfigMap.get("HOTPOTJUMP_END_PARAM").getIntValue();
        practiceMaxRound = activityConfigMap.get("HOTPOTJUMP_GUIDE_END_ROUND").getIntValue();
        reviveConsume = PropertyHelper.parseStringToProperty(activityConfigMap.get("HOTPOTJUMP_REVIVE_CONSUME").getValue());
        reviveLimit = activityConfigMap.get("HOTPOTJUMP_REVIVE_TIMES").getIntValue();
        reviveHpRate = activityConfigMap.get("HOTPOTJUMP_REVIVE_RECOVER_HP").getIntValue();
        skillMaxNum = activityConfigMap.get("HOTPOTJUMP_SKILL_SLOT").getIntValue();
        bossRound = new ArrayList<>();
        for (String s : activityConfigMap.get("HOTPOTJUMP_BOSS_ROUND").getValue().split("\\|")) {
            List<Integer> list = StringUtils.stringToIntegerList(s, ",");
            bossRound.add(list);
        }
        initPos = StringUtils.stringToIntegerList(activityConfigMap.get("HOTPOTJUMP_PLAYER_INITIAL_COORDINATE").getValue(), ",").toArray(new Integer[2]);
        for (String str : activityConfigMap.get("HOTPOTJUMP_INITIAL_PARAM").getValue().split("\\|")) {
            initialEnemyList.add(StringUtils.stringToIntegerList(str, ","));
        }

        extraEnemyNum = activityConfigMap.get("HOTPOTJUMP_INITIAL_RANDOM_PARAM").getIntValue();
        combSkillNeed = activityConfigMap.get("HOTPOTJUMP_COMBO_SKILL_LIMIT").getIntValue();
        silverCombSkillNeed = activityConfigMap.get("HOTPOTJUMP_BATTLE_PASS_COMBO_SKILL").getIntValue();
        moveAtkMulti = activityConfigMap.get("HOTPOTJUMP_MOVE_DAMAGE").getIntValue();

        for (String str : activityConfigMap.get("HOTPOTJUMP_BOSS_PARAM").getValue().split("\\|")) {
            bossSortList.add(StringUtils.stringToIntegerList(str, ","));
        }
        bossExpAdd = activityConfigMap.get("HOTPOTJUMP_BOSS_EXP").getIntValue();
        for (String str : activityConfigMap.get("HOTPOTJUMP_MONSTER_RULER").getValue().split("\\|")) {
            createPosRuleParams.add(StringUtils.stringToIntegerList(str, ","));
        }
        tokenScoreMulti = activityConfigMap.get("HOTPOTJUMP_BATTLE_PASS_DOLL_PARAM").getIntValue();
        tokenDollId = activityConfigMap.get("HOTPOTJUMP_BATTLE_PASS_DOLL").getIntValue();

        guideSkillPool = StringUtils.stringToIntegerList(activityConfigMap.get("HOTPOTJUMP_GUIDE_SKILL_POUND").getValue(), "\\|");
        HOTPOTJUMP_GUIDE_SCENE_1 = activityConfigMap.get("HOTPOTJUMP_GUIDE_SCENE_1").getValue();
        HOTPOTJUMP_GUIDE_SCENE_2 = activityConfigMap.get("HOTPOTJUMP_GUIDE_SCENE_2").getValue();
        HOTPOTJUMP_GUIDE_SCENE_3 = activityConfigMap.get("HOTPOTJUMP_GUIDE_SCENE_3").getValue();
        guideSelectSkillIdx = activityConfigMap.get("HOTPOTJUMP_GUIDE_SKILL_SELECT").getIntValue();

        if (activityConfigMap.containsKey("HOTPOTJUMP_BLOOD_WEIGHT_UP")) {
            List<Integer> list = StringUtils.stringToIntegerList(activityConfigMap.get("HOTPOTJUMP_BLOOD_WEIGHT_UP").getValue(), "\\|");
            hpSkillWeightCheckValue = list.get(0);
            hpSkillWeightMulti = list.get(1);
        }

        if (activityConfigMap.containsKey("HOTPOTJUMP_ROUND_END_ADD_SCORE")) {
            this.HOTPOTJUMP_ROUND_END_ADD_SCORE = activityConfigMap.get("HOTPOTJUMP_ROUND_END_ADD_SCORE").getIntValue();
        }
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public int getActivityId() {
        return activityInfo.getActivityId();
    }

    public HotpotJumpProto.HotpotJumpConfigSyncMsg.Builder getConfigMsg(String language) {
        return configMsgMap.get(language);
    }

    public void setConfigMsg(String language, HotpotJumpProto.HotpotJumpConfigSyncMsg.Builder configMsg) {
        configMsgMap.put(language, configMsg);
    }

    public Map<Integer, HotpotJumpSkillConfig> getSkillConfigMap() {
        return new HashMap<>(skillConfigMap);
    }

    public Map<Integer, HotpotJumpLevelConfig> getLevelConfigMap() {
        return new HashMap<>(levelConfigMap);
    }

    public List<HotpotJumpMissionConfig> getMissionConfigs() {
        return new ArrayList<>(missionConfigs);
    }

    public Map<Integer, HotpotJumpModelConfig> getModelConfigMap() {
        return new HashMap<>(modelConfigMap);
    }


    public List<HotpotJumpNumConfig> getNumConfigList() {
        return new ArrayList<>(numConfigList);
    }

    public Map<Integer, HotpotJumpPotConfig> getPotConfigMap() {
        return new HashMap<>(potConfigMap);
    }

    public Map<String, HotpotJumpProto.HotpotJumpConfigSyncMsg.Builder> getConfigMsgMap() {
        return configMsgMap;
    }

    public Property getEnergyCost() {
        return new Property(energyCost);
    }

    public int getDayNum() {
        return dayNum;
    }

    public int getRefreshItemId() {
        return refreshItemId;
    }

    public HotpotJumpEvaluateConfig[] getEvaluateConfigs() {
        return evaluateConfigs;
    }

    public HotpotJumpCombConfig[] getCombConfigs() {
        return combConfigs;
    }

    public int getMaxRound() {
        return maxRound;
    }

    public Property getReviveConsume() {
        return reviveConsume;
    }

    public int getReviveLimit() {
        return reviveLimit;
    }

    public int getReviveHpRate() {
        return reviveHpRate;
    }

    public int getSkillMaxNum() {
        return skillMaxNum;
    }

    public List<List<Integer>> getBossRound() {
        return bossRound;
    }

    public Integer[] getInitPos() {
        return initPos;
    }


    public int getCombSkillNeed() {
        return combSkillNeed;
    }

    public int getSilverCombSkillNeed() {
        return silverCombSkillNeed;
    }

    public int getMoveAtkMulti() {
        return moveAtkMulti;
    }

    public int randomPotId() {
        Integer potId = RandomHelper.getRandomElement(new ArrayList<>(potConfigMap.keySet()));
        return potId;
    }

    public HotpotJumpModelConfig getModelConfigByType(int type) {
        for (HotpotJumpModelConfig modelConfig : modelConfigMap.values()) {
            if (modelConfig.getType() == type) {
                return modelConfig;
            }
        }
        return null;
    }

    public HotpotJumpModelConfig getModelConfigById(int id) {
        for (HotpotJumpModelConfig modelConfig : modelConfigMap.values()) {
            if (modelConfig.getId() == id) {
                return modelConfig;
            }
        }
        return null;
    }

    /**
     * 初始化一个主角数据
     *
     * @return
     */
    public HotpotJumpMainRole initMainRole() {
        HotpotJumpMainRole mainRole = new HotpotJumpMainRole();
        mainRole.setLv(1);
        mainRole.setExp(0);

        Map<eHotpotJumpAttr, Integer> attrMap = calcMainRoleAttr(mainRole);

        HotpotJumpGrid grid = new HotpotJumpGrid(getInitPos()[0], getInitPos()[1]);
        grid.setHpMax(attrMap.get(eHotpotJumpAttr.Hp));
        grid.setHp(grid.getHpMax());
        mainRole.setGrid(grid);
        mainRole.setAttrMap(attrMap);

        return mainRole;
    }

    public Map<eHotpotJumpAttr, Integer> calcMainRoleAttr(HotpotJumpMainRole mainRole) {
        HotpotJumpModelConfig modelConfig = getModelConfigByType(eHotpotJumpUnit.MainRole.getValue());
        HotpotJumpLevelConfig levelConfig = null;
        for (HotpotJumpLevelConfig tempConfig : mainLevelConfigs) {
            if (tempConfig.getLevel() == mainRole.getLv()) {
                levelConfig = tempConfig;
                break;
            }
        }

        Map<eHotpotJumpAttr, Integer> attrMap = new HashMap<>();
        BigDecimal atk = BigDecimal.valueOf(modelConfig.getAtk()).multiply(BigDecimal.valueOf(levelConfig.getAtkIncrease()).divide(BigDecimal.valueOf(1000)));
        BigDecimal hp = BigDecimal.valueOf(modelConfig.getHp()).multiply(BigDecimal.valueOf(levelConfig.getHpIncrease()).divide(BigDecimal.valueOf(1000)));
        attrMap.put(eHotpotJumpAttr.Atk, atk.intValue());
        attrMap.put(eHotpotJumpAttr.Hp, hp.intValue());
        attrMap.put(eHotpotJumpAttr.CriticalRate, modelConfig.getCriticalRate());

        for (List<Integer> skill : mainRole.getSkills()) {
            int skillId = skill.get(0);
            int skillLevel = skill.get(1);
            HotpotJumpSkillConfig skillConfig = getSkillConfigMap().get(skillId);
            if (skillConfig == null) {
                continue;
            }

            HotpotJumpSkillEffect skillEffect = skillConfig.skillEffect;
            if (skillEffect.getEffectType() != eHotpotJumpEffect.AttrChange.getValue()) {
                continue;
            }

            int attrType = skillEffect.getEffectShow();
            int attrValue = skillEffect.getValueByLevel(skillLevel);
            eHotpotJumpAttr eAttrType = eHotpotJumpAttr.getByValue(attrType);
            if (eAttrType == null) {
                continue;
            }
            attrMap.put(eAttrType, attrMap.getOrDefault(eAttrType, 0) + attrValue);
        }
        return attrMap;
    }

    /**
     * 初始小怪
     *
     * @return
     */
    public List<HotpotJumpUnit> initEnemyList(HotpotJumpGameLogic gameLogic) {
        List<HotpotJumpUnit> result = new ArrayList<>();
        for (List<Integer> list : initialEnemyList) {
            Integer modelId = list.get(0);
            Integer x = list.get(1);
            Integer y = list.get(2);
            int rewardExp = list.get(3);

            HotpotJumpModelConfig modelConfig = getModelConfigById(modelId);
            if (modelConfig == null) {
                continue;
            }

            List<Integer> attrs = calcUnitAtkAndHp(modelConfig, 1);

            JumpBoardGrid emptyGrid = gameLogic.board.findGrid(x, y);

            HotpotJumpUnit unit = gameLogic.createJumpUnit(modelId, 1, rewardExp, attrs.get(1), attrs.get(0), emptyGrid);

            result.add(unit);

        }
        return result;
    }

    /**
     * 练习模式初始小怪
     *
     * @return
     */
    public List<HotpotJumpUnit> initGuideEnemyList(HotpotJumpGameLogic gameLogic, int round) {
        List<HotpotJumpUnit> result = new ArrayList<>();
        String str = "";
        if (round == 1) {
            str = HOTPOTJUMP_GUIDE_SCENE_1;
        } else if (round == 2) {
            str = HOTPOTJUMP_GUIDE_SCENE_2;
        } else {
            str = HOTPOTJUMP_GUIDE_SCENE_3;
        }
        List<String> strings = StringUtils.stringToStringList(str, "#");
        List<List<Integer>> guideEnemyList = new ArrayList<>();
        for (String s : strings.get(0).split("\\|")) {
            guideEnemyList.add(StringUtils.stringToIntegerList(s, ","));
        }
        for (List<Integer> list : guideEnemyList) {
            Integer modelId = list.get(0);
            Integer x = list.get(1);
            Integer y = list.get(2);
            int rewardExp = list.get(3);

            HotpotJumpModelConfig modelConfig = getModelConfigById(modelId);
            if (modelConfig == null) {
                continue;
            }

            List<Integer> attrs = calcUnitAtkAndHp(modelConfig, 1);

            JumpBoardGrid emptyGrid = gameLogic.board.findGrid(x, y);

            HotpotJumpUnit unit = gameLogic.createJumpUnit(modelId, 1, rewardExp, attrs.get(1), attrs.get(0), emptyGrid);

            result.add(unit);

        }
        return result;
    }

    public List<Integer> calcUnitAtkAndHp(HotpotJumpModelConfig modelConfig, int level) {
        List<Integer> result = new ArrayList<>();
        HotpotJumpLevelConfig levelConfig = unitLevelConfigMap.get(level);
        BigDecimal atk = BigDecimal.valueOf(modelConfig.getAtk()).multiply(BigDecimal.valueOf(levelConfig.getAtkIncrease()).divide(BigDecimal.valueOf(1000))).setScale(0, RoundingMode.UP);
        BigDecimal hp = BigDecimal.valueOf(modelConfig.getHp()).multiply(BigDecimal.valueOf(levelConfig.getHpIncrease()).divide(BigDecimal.valueOf(1000))).setScale(0, RoundingMode.UP);
        result.add(atk.intValue());
        result.add(hp.intValue());
        return result;
    }

    public HotpotJumpEvaluateConfig calcEvaluate(int score) {
        HotpotJumpEvaluateConfig result = null;
        for (HotpotJumpEvaluateConfig config : evaluateConfigs) {
            if (score >= config.getScore()) {
                result = config;
            }
        }
        return result;
    }

    public boolean isBoss(int configId) {
        HotpotJumpModelConfig modelConfig = getModelConfigById(configId);
        return modelConfig.getType() != eHotpotJumpUnit.Normal.getValue() && modelConfig.getType() != eHotpotJumpUnit.MainRole.getValue();
    }

    /**
     * 判断一下是不是特殊BOSS,乌龟只有中间的点可以跳,并且其他的点不影响
     *
     * @param configId
     * @return
     */
    public boolean isBoss3(int configId) {
        HotpotJumpModelConfig modelConfig = getModelConfigById(configId);
        return modelConfig.getType() == eHotpotJumpUnit.Boss3.getValue();
    }

    public boolean isBoss2(int configId) {
        HotpotJumpModelConfig modelConfig = getModelConfigById(configId);
        return modelConfig.getType() == eHotpotJumpUnit.Boss2.getValue();
    }

    public boolean isBoss1(int configId) {
        HotpotJumpModelConfig modelConfig = getModelConfigById(configId);
        return modelConfig.getType() == eHotpotJumpUnit.Boss1.getValue();
    }

    public boolean isBoss4(int configId) {
        HotpotJumpModelConfig modelConfig = getModelConfigById(configId);
        return modelConfig.getType() == eHotpotJumpUnit.Boss4.getValue();
    }

    public HotpotJumpSkillRange findSkillRange(HotpotJumpSkillConfig skillConfig, int skillLv) {
        HotpotJumpSkillRange result = null;
        for (HotpotJumpSkillRange skillRange : skillConfig.skillRanges) {
            if (skillLv >= skillRange.getLevel()) {
                result = skillRange;
            }
        }
        return result;
    }

    public int getModelScore(int configId) {
        HotpotJumpModelConfig modelConfig = getModelConfigById(configId);
        if (modelConfig == null) {
            return 0;
        }
        return modelConfig.getScore();
    }

    public int calcMainRoleLevel(int totalExp) {
        int remainExp = totalExp;
        int level = 1;
        for (HotpotJumpLevelConfig levelConfig : mainLevelConfigs) {
            if (levelConfig == mainLevelConfigs.get(mainLevelConfigs.size() - 1)) {
                break;
            }
            if (remainExp < levelConfig.getExp()) {
                break;
            }
            remainExp -= levelConfig.getExp();
            level = levelConfig.getLevel() + 1;
        }
        return level;
    }

    public HotpotJumpLevelConfig getMainRoleLevelConfig(int level) {
        for (HotpotJumpLevelConfig levelConfig : mainLevelConfigs) {
            if (levelConfig.getLevel() == level) {
                return levelConfig;
            }
        }
        return null;
    }

    /**
     * 根据主角已有的技能随机技能
     *
     * @param skills
     * @param isGuide
     * @param remainHpRate 主角剩余血量千分比
     * @return
     */
    public List<Integer> randomMainRoleSkill(List<List<Integer>> skills, boolean isGuide, int remainHpRate) {
        if (isGuide) {
            return guideSkillPool;
        }
        List<Integer> result = new ArrayList<>();

        Set<Integer> excludeSkillSet = new HashSet<>();
        Set<Integer> notFullSkillSet = new HashSet<>();
        boolean isAllFull = true;
        for (List<Integer> skill : skills) {
            int skillId = skill.get(0);
            int skillLv = skill.get(1);

            HotpotJumpSkillConfig skillConfig = getSkillConfigMap().get(skillId);
            if (skillLv >= skillConfig.getMaxLevel()) {
                excludeSkillSet.add(skillId);
            } else {
                isAllFull = false;
                notFullSkillSet.add(skillId);
            }
        }

        Map<Integer, Integer> weightMap = new HashMap<>();
        if (skills.size() >= getSkillMaxNum()) {//技能满了,只能在已有未满级技能里随机
            for (HotpotJumpSkillConfig skillConfig : skillConfigMap.values()) {
                if (skillConfig.getSort() == 1) {
                    if (!notFullSkillSet.contains(skillConfig.getId())) {
                        continue;
                    }
                } else if (skillConfig.getSort() != 2) {
                    continue;
                }

                if (skillConfig.skillEffect.getEffectType() == eHotpotJumpEffect.Heal.getValue()) {
                    if (remainHpRate <= hpSkillWeightCheckValue) {
                        int newWeight = BigDecimal.valueOf(skillConfig.getWeight() * hpSkillWeightMulti).divide(BigDecimal.valueOf(1000), 0, RoundingMode.UP).intValue();
                        weightMap.put(skillConfig.getId(), newWeight);
                    } else {
                        weightMap.put(skillConfig.getId(), skillConfig.getWeight());
                    }
                } else {
                    weightMap.put(skillConfig.getId(), skillConfig.getWeight());
                }
            }
        } else {
            isAllFull = false;
            for (HotpotJumpSkillConfig skillConfig : skillConfigMap.values()) {
                if (isAllFull) {//技能满了并且全满级,只能在分类2里随机
                    if (skillConfig.getSort() != 2) {
                        continue;
                    }
                } else if (skillConfig.getSort() != 1 && skillConfig.getSort() != 2) {
                    continue;
                }

                if (excludeSkillSet.contains(skillConfig.getId())) {
                    continue;
                }

                if (skillConfig.skillEffect.getEffectType() == eHotpotJumpEffect.Heal.getValue()) {
                    if (remainHpRate <= hpSkillWeightCheckValue) {
                        int newWeight = BigDecimal.valueOf(skillConfig.getWeight() * hpSkillWeightMulti).divide(BigDecimal.valueOf(1000), 0, RoundingMode.UP).intValue();
                        weightMap.put(skillConfig.getId(), newWeight);
                    } else {
                        weightMap.put(skillConfig.getId(), skillConfig.getWeight());
                    }
                } else {
                    weightMap.put(skillConfig.getId(), skillConfig.getWeight());
                }
            }
        }

        for (int i = 0; i < 3; i++) {
            if (weightMap.isEmpty()) {
                break;
            }
            int skillId = randomHelper.getRandomKeyByWeightEx(weightMap);
            weightMap.remove(skillId);

            result.add(skillId);
        }
        return result;
    }

    public List<Property> getRefreshCostList() {
        return new ArrayList<>(refreshCostList);
    }

    public List<Integer> randomBossSort() {
        int idx = randomHelper.next(bossSortList.size());
        List<Integer> list = bossSortList.get(idx);
        List<Integer> bossList = new ArrayList<>(list);
        return bossList;
    }

    public HotpotJumpMissionConfig getFirstMissionConfig() {
        return missionConfigs.get(0);
    }

    public HotpotJumpMissionConfig getMissionConfig(int missionId) {
        for (HotpotJumpMissionConfig missionConfig : missionConfigs) {
            if (missionConfig.getId() == missionId) {
                return missionConfig;
            }
        }
        return null;
    }

    public HotpotJumpMissionConfig getNextMissionConfig(int missionId) {
        for (HotpotJumpMissionConfig missionConfig : missionConfigs) {
            if (missionConfig.getId() > missionId) {
                return missionConfig;
            }
        }

        return missionConfigs.get(missionConfigs.size() - 1);
    }

    public List<List<Integer>> getUnionPool(HotpotJumpMissionConfig missionConfig) {
        List<List<Integer>> result = new ArrayList<>();
        for (List<Integer> poolParam : missionConfig.poolParams) {
            result.add(new ArrayList<>(poolParam));
        }
        return result;
    }

    public HotpotJumpNumConfig getNumConfigByRound(int round) {
        HotpotJumpNumConfig result = null;
        for (HotpotJumpNumConfig numConfig : numConfigList) {
            if (round > numConfig.getRound()) {
                result = numConfig;
            }
        }
        return result;
    }

    public int getBossExpAdd() {
        return bossExpAdd;
    }

    public List<Integer> getCreatePosRuleParams(int round) {
        List<Integer> result = new ArrayList<>();
        for (List<Integer> list : createPosRuleParams) {
            int compareRound = list.get(0);
            if (round >= compareRound) {
                result = new ArrayList<>(list);
            }
        }
        return result;
    }

    public int getExtraEnemyNum() {
        return extraEnemyNum;
    }

    public int getTokenScoreMulti() {
        return tokenScoreMulti;
    }

    public int getTokenDollId() {
        return tokenDollId;
    }

    public int getPracticeMaxRound() {
        return practiceMaxRound;
    }

    public List<Integer> getGuideSkillPool() {
        return guideSkillPool;
    }

    public String getHOTPOTJUMP_GUIDE_SCENE_1() {
        return HOTPOTJUMP_GUIDE_SCENE_1;
    }

    public String getHOTPOTJUMP_GUIDE_SCENE_2() {
        return HOTPOTJUMP_GUIDE_SCENE_2;
    }

    public String getHOTPOTJUMP_GUIDE_SCENE_3() {
        return HOTPOTJUMP_GUIDE_SCENE_3;
    }

    public int getGuideSelectSkillIdx() {
        return guideSelectSkillIdx;
    }

    public List<List<Integer>> getGuideMove(int round) {
        List<List<Integer>> result = new ArrayList<>();
        String str = "";
        if (round == 1) {
            str = HOTPOTJUMP_GUIDE_SCENE_1;
        } else if (round == 2) {
            str = HOTPOTJUMP_GUIDE_SCENE_2;
        } else {
            str = HOTPOTJUMP_GUIDE_SCENE_3;
        }
        List<String> strings = StringUtils.stringToStringList(str, "#");
        for (String s : strings.get(1).split("\\|")) {
            result.add(StringUtils.stringToIntegerList(s, ","));
        }
        return result;
    }

    public int getJumpAtkMulti(int jumpNum) {
        HotpotJumpCombConfig findConfig = null;
        for (HotpotJumpCombConfig combConfig : combConfigs) {
            if (jumpNum >= combConfig.getCombNum()) {
                findConfig = combConfig;
            }
        }
        if (findConfig == null) {
            return 1000;
        }

        return findConfig.getDamageMulti();
    }

    public int getJumpScoreMulti(int jumpNum) {
        HotpotJumpCombConfig findConfig = null;
        for (HotpotJumpCombConfig combConfig : combConfigs) {
            if (jumpNum >= combConfig.getCombNum()) {
                findConfig = combConfig;
            }
        }
        if (findConfig == null) {
            return 1000;
        }

        return findConfig.getScoreMulti();
    }

    public int getHpSkillWeightCheckValue() {
        return hpSkillWeightCheckValue;
    }

    public void setHpSkillWeightCheckValue(int hpSkillWeightCheckValue) {
        this.hpSkillWeightCheckValue = hpSkillWeightCheckValue;
    }

    public int getHpSkillWeightMulti() {
        return hpSkillWeightMulti;
    }

    public void setHpSkillWeightMulti(int hpSkillWeightMulti) {
        this.hpSkillWeightMulti = hpSkillWeightMulti;
    }

    public int getHOTPOTJUMP_ROUND_END_ADD_SCORE() {
        return HOTPOTJUMP_ROUND_END_ADD_SCORE;
    }
}
